<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.hehe{
    width: 200px;
    height: 100px;
    background-color: blue;
}
</style>
</head>
<body>
    
<div class="box1">一个块1</div>
<div class="box2">一个块2</div>
<div class="box3 red green">一个块3</div>

<script>
// 获取元素
var box1 = document.querySelector('.box1');
var box2 = document.querySelector('.box2');
var box3 = document.querySelector('.box3');

// 每一个元素节点都有一个style属性，值为一个样式预设对象
// 节点对象都预设了所有的样式，初始值都为''
console.log( box1.style );// {样式预设对象}
console.log( box2.style );// {样式预设对象}
console.log( box3.style );// {样式预设对象}

// 1.修改元素节点的样式：在行内设置样式
box1.style.width = '200px';
box1.style.height = '100px';
box1.style.backgroundColor = 'pink';

// 2.修改元素节点的样式：在行内设置样式
box2.style.cssText = 'width:200px;height:100px;background-color:red;'

// 3.修改元素节点的样式：修改元素的类名
// box3.className = 'box3 red green'原来的类名
// box3.className = 'box3 red green hehe';
// box3.className = box3.className + ' hehe';
box3.className += ' hehe';

</script>
</body>
</html>